package com.hmall.cart.listener;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hmall.api.dto.CartClearDTO;
import com.hmall.cart.domain.po.Cart;
import com.hmall.cart.service.ICartService;
import com.hmall.common.constants.MqConstants;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class TradeStatusListener {
    @Autowired
    private ICartService cartService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(MqConstants.TRADE_SUCCESS_QUEUE),
            exchange = @Exchange(value = MqConstants.TRADE_EXCHANGE_NAME),
            key = MqConstants.TRADE_SUCCESS_KEY
    ))
    public void tradeSuccessListener(CartClearDTO dto){
        cartService.remove(Wrappers.<Cart>lambdaQuery().eq(Cart::getUserId,dto.getUserId()).in(Cart::getItemId,dto.getItemIds()));
    }
}
